package www.wen.com.common.lib.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import www.wen.com.common.R
import www.wen.com.common.databinding.UnreadDotBinding
import www.wen.com.common.lib.extension.dp
import www.wen.com.common.lib.extension.unread
import www.wen.com.common.lib.util.DisplayUtil

class UnreadDot @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : RelativeLayout(context, attrs) {
    private val binding: UnreadDotBinding =
        DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.unread_dot, this, true)

    var unreadCount:Int = 0
        set(value) {
            binding.tvUnreadMessage.text = value.unread()
            binding.slUnreadMessage.isVisible = value > 0
            field = value
        }

    var textSize:Float = 8f
    set(value) {
        binding.tvUnreadMessage.textSize = DisplayUtil.px2sp(value)
        field = value
    }

}